import React, { Component } from 'react';
// import { Router } from 'react-router-dom';
import history from './history'
import Header from './components/Header';
import Footer from './components/Footer';
import CompanyContent from './components/CompanyContent';
import CompanyTab from './components/CompanyTab';
import Login from './Login'
import './App.css';
// import App from './App'
// import ReactDOM from 'react-dom';

class CompanyApp extends Component {
  constructor(props) {
    super(props)
    this.state = {
      userName: '',
      showLogin: false
    }
    this.loginSuccess = this.loginSuccess.bind(this)
  }
  

  onLogin() {
    //禁止滚动
    document.body.style.overflow = 'hidden'
    this.setState({
      showLogin: true
    })
  }

  onClose() {
    document.body.style.overflow = 'auto'
    this.setState({
      showLogin: false
    })
  }

  loginSuccess() {
    this.onClose()
  }

  onForget() {
    this.onClose()
    history.push('/mainPage/resetPwd')
  }

  onRegister() {
    history.push('/mainPage/register')
  }

  goMain() {
    history.replace('/mainPage/main')
  }

  render() {
    const { showLogin } = this.state
    return (
      <div className="">
        {showLogin && <Login 
          onClose={() => this.onClose()} 
          onForget={() => this.onForget()}
          loginSuccess={this.loginSuccess}
        />}
        <Header
          onLogin={() => this.onLogin()}
          onRegister={() => this.onRegister()} 
          onGoMain={() => this.goMain()}
        />
        <CompanyTab />
        <CompanyContent />
        <Footer />
      </div>
    );
  }
}

export default CompanyApp;
